//
//  CDrawNumberW.m
//  FrameWork
//
//  Created by waver on 10-8-9.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "CDrawNumberW.h"
#import "Methods.h"


@implementation CDrawNumberW

+(id)Create
{
	return [[super node]InitCreate];
}

-(id)InitCreate
{
	__number = 0;
	__imageName=nil;
	return self;
}

-(void)DrawNumber:(int)num  FirstPoint:(CGPoint) drawPoint xOff:(int)x_off;
{
	__number = num;
	CCTexture2D *pt = [[CCTextureCache sharedTextureCache] addImage:__imageName];
	int numWidth = pt.contentSize.width/11;
	int numHeight = pt.contentSize.height;
	position_.x = drawPoint.x + numWidth/2;
	position_.y = drawPoint.y - numHeight/2;
	int x_dis =self.contentSize.width/2;
	int y_dis = self.contentSize.height/2;
	int a = PubMethod::GetNumberBit(num);
	for(int i = a;i>0;i--)
	{
		int n = PubMethod::GetBitNumber(num, i);
		CGRect re = CGRectMake(numWidth*n, 0, numWidth , numHeight);
		CCSprite * m = [CCSprite spriteWithTexture:pt rect:re];
		m.position = CGPointMake(x_dis, y_dis);
		[self addChild:m z:10];
		x_dis = x_dis + numWidth +x_off;
	}
}

-(void)NumberImage:(NSString*)numImage
{
	if(__imageName != nil)
	{
		[__imageName release];
	}
	__imageName = [NSString stringWithString:numImage];
	[[CCTextureCache sharedTextureCache] addImage:__imageName];
}

@end
